



var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Components.interfaces.nsINavBookmarksService);



// An nsINavBookmarkObserver
var myExt_bookmarkListener = {
	
	onBeginUpdateBatch: function() {},
	
	onEndUpdateBatch: function() {},
	
	onItemAdded: function(aItemId, aFolder, aIndex) {
		bm_list.itemAdded(aItemId, aFolder, aIndex);
	},
	
	onItemRemoved: function(aItemId, aFolder, aIndex) {
		bm_list.itemRemoved(aItemId, aFolder, aIndex);
	},
	
	onItemChanged: function(aBookmarkId, aProperty, aIsAnnotationProperty, aValue) {},
	
	onItemVisited: function(aBookmarkId, aVisitID, time) {},
	
	onItemMoved: function(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex) {},
	
	QueryInterface: function(iid) {
		if (iid.equals(Ci.nsINavBookmarkObserver) || iid.equals(Ci.nsISupports)) {
			return this;
		}
		throw Cr.NS_ERROR_NO_INTERFACE;
	}
	
};


var event_handler = Components.classes["@mozilla.org/EventHandlers;1"].getService(Components.interfaces.nsIEventHandlers);


// An extension
var bm_list = {
	
	onLoad: function() {
		bmsvc.addObserver(myExt_bookmarkListener, false);
	},
	
	onUnLoad: function() {
		bmsvc.removeObserver(myExt_bookmarkListener);
	},
	
	itemAdded: function(aItemId, aFolder, aIndex) {
		
		// tell the handler that an item has been added
		event_handler.placesItemAdded(aItemId, aFolder, aIndex);
		
	},
	
	itemRemoved: function(aItemId, aFolder, aIndex) {
		
		// tell the handler that an item has been removed
		event_handler.placesItemRemoved(aItemId, aFolder, aIndex);
		
	},
	
};


window.addEventListener("load", function() {bm_list.onLoad()}, false);
window.addEventListener("unload", function() {bm_list.onUnLoad()}, false);
